<template>
  <div class="d-scroll listInner bg-white p-1">
    <div class="addCheckOpinions p-1">
      <el-form ref="addEditForm" :model="addEditForm" :rules="addEditRules" size="small" label-position="top">
        <el-form-item label="核查地区：" prop="hcdq">
          <el-input v-model="addEditForm['hcdq']" disabled placeholder="请输入核查地区" clearable maxlength="50" />
        </el-form-item>
        <el-form-item label="核查对象名称：" prop="wrymc">
          <el-input v-model="addEditForm['wrymc']" disabled placeholder="请输入核查对象名称" clearable maxlength="50" />
        </el-form-item>
        <el-form-item label="问题类型：" prop="wtlx">
          <custom-vant-select :select-value.sync="addEditForm.wtlx" :colums="questionTypeList" picker-title="请选择问题类型" @confirm="handleEventLevel" />
        </el-form-item>
        <el-form-item label="核查意见：" prop="auditOption">
          <el-input v-model="addEditForm['auditOption']" type="textarea" placeholder="请输入核查意见" />
        </el-form-item>
        <el-form-item label="核查人员：" prop="hcry">
          <el-input v-model="addEditForm['hcry']" placeholder="请输入核查人员" clearable maxlength="50" />
        </el-form-item>
        <el-form-item label="现场照片/视频：" prop="eventResearch">
          <base-upload ref="upload1" type="file" show-type="li" class="w-100" @uploadCallback="uploadCallback($event, 'addEditForm', 'upload1', 'eventResearch')" @deleteCallback="uploadCallback($event, 'upload1', 'eventResearch')" />
        </el-form-item>
        <el-form-item label-width="0px" class="text-center">
          <el-button class="custom-button" @click="$emit('cancel', false)">取消</el-button>
          <el-button class="custom-button mr-1" type="primary" :loading="sureLoading" @click="handleConfirmAddEdit">确认</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>

import commonList from '@/assets/mixin/commonList'
import CustomVantSelect from '@/components/globals/custom-vant-select.vue'
import baseUpload from '@/components/common/reportUpload.vue'
import { addOption } from '@/api/special'
import { Toast } from 'vant'

export default {
  id: 'addCheckOpinions',
  components: { CustomVantSelect, baseUpload },
  mixins: [commonList],
  props: {
    /**
     * 当前企业项
     */
    dataItem: {
      type: Object,
      default: () => {}
    },
    /**
     * 任务ID
     */
    taskId: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      sureLoading: false,
      questionTypeList: [
        { text: '漏查', value: '漏查' },
        { text: '数据有误', value: '数据有误' },
        { text: '其他', value: '其他' }
      ],
      addEditRules: {
        hcdq: [{ required: true, message: '请输入核查地区', trigger: 'change' }],
        auditOption: [{ required: true, message: '请输入核查意见', trigger: 'change' }],
        wrymc: [{ required: true, message: '请输入核查对象名称', trigger: 'change' }],
        hcry: [{ required: true, message: '请输入核查人员', trigger: 'change' }],
        wtlx: [{ required: true, message: '请选择事故等级', trigger: 'change' }]
      }, // 表单校验规则
      addEditForm: {
        encryptions: true,
        hcfiles: '[]',
        taskid: '', // 任务ID
        id: '',
        hcdq: '', // 核查地区
        wrymc: '', // 核查对象名称
        auditOption: '', // 核查意见
        hcry: '', // 核查人员
        wtlx: '' // 问题类型
      } // 添加检查意见表单
    }
  },
  methods: {
    /**
     * 初始化表单字段
     */
    initFormFiledName() {
      this.addEditForm.hcdq = this.dataItem['districtName']
      this.addEditForm.wrymc = this.dataItem['danweiName']
      console.log(this.dataItem)
    },
    /**
     * 切换问题类型
     * @param item
     */
    handleEventLevel(item) {
      if (item) {
        this.addEditForm.wtlx = item.value
      }
    },
    /**
     * 重置表单
     */
    resetFrom() {
      this.$refs.addEditForm.resetFields()
    },
    /**
     * 确认
     */
    handleConfirmAddEdit() {
      this.$refs.addEditForm.validate(async(valid) => {
        if (valid) {
          try {
            this.sureLoading = true
            this.addEditForm.taskid = this.taskId
            const { status, data } = await addOption(this.addEditForm)
            if (status && data) {
              console.log('data', data)
              Toast.success(data)
              this.$emit('cancel', false)
              this.sureLoading = false
            } else {
              setTimeout(() => {
                this.sureLoading = false
              }, 800)
            }
            console.log(this.addEditForm)
          } catch (err) {
            this.sureLoading = false
            console.log(err)
          }
        } else {
          console.log('检验不通过！！！')
          return false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.addCheckOpinions {
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: #eef1f3;
}
::v-deep .custom-button {
  padding: 26px 60px;
  font-size: 0.32rem !important;
}
</style>
